<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="conteudo">
		<ui:param name="actionBean" value="#{historicoClinicoMB}" />
		<h:form id="frm">

			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />

		</h:form>

		<h:form id="frmTab">
			<p:commandButton id="btnCancelar" action="#{historicoClinicoMB.sair}"
				style="display:none" immediate="true" value="cancelar" />
			<p:commandButton actionListener="#{historicoClinicoMB.abrirModal}"
				title="Incluir" update=":frmDialogHistoricoClinico" value="Novo Registro"
				style="float:left" icon="ui-icon-disk"  ajax="true"
				oncomplete="dialogCadastroHistoricoClinico.show()">
				<f:param name="modooperacao" value="INCLUIR" />
			</p:commandButton>
			<p:dataTable id="tabela" var="item"
				value="#{historicoClinicoMB.lista}" paginator="true" rows="10"
				emptyMessage="Não há registros"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" paginatorPosition="bottom"
				selectionMode="single" rowKey="#{item.codigo}">
				<f:facet name="header">Histórico Clínico
				</f:facet>
				<p:column headerText="Codigo" sortBy="#{item.codigo}">
					<h:outputText value="#{item.codigo}" />
				</p:column>

				<p:column headerText="Usuário" sortBy="#{item.usuario.nome}">

					<h:outputText value="#{item.usuario.nome}" />

				</p:column>

				<p:column headerText="Cliente"
					sortBy="#{item.animal.cliente.dadosCadastro.nome}">

					<h:outputText value="#{item.animal.cliente.dadosCadastro.nome}" />

				</p:column>

				<p:column headerText="Animal" sortBy="#{item.animal.nomeAnimal}">

					<h:outputText value="#{item.animal.nomeAnimal}" />

				</p:column>



				<p:column headerText="Ações" style="text-align:center">

					<p:commandButton title="Alterar" icon="ui-icon-pencil" styleClass="styleBotao"
						actionListener="#{historicoClinicoMB.abrirModal}"
						update=":frmDialogHistoricoClinico,:dialogCadastroHist"
						oncomplete="dialogCadastroHistoricoClinico.show()">

						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{historicoClinicoMB.historicoClinicoSelecionado}" />
						<f:param name="modooperacao" value="ALTERAR" />
					</p:commandButton>

					<p:commandButton actionListener="#{historicoClinicoMB.abrirModal}" styleClass="styleBotao"
						title="Consultar" update=":frmDialogHistoricoClinico" 
						oncomplete="dialogCadastroHistoricoClinico.show()"
						icon="ui-icon-search">
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{historicoClinicoMB.historicoClinicoSelecionado}" />
						<f:param name="modooperacao" value="CONSULTAR" />
					</p:commandButton>

					<p:commandButton title="Excluir" update=":Excluir"
						rendered="#{historicoClinicoMB.verificaPermissaoCadastro()}"
						oncomplete="confirmation.show()" styleClass="styleRed"
						icon="ui-icon-close">
						<f:setPropertyActionListener
							target="#{historicoClinicoMB.historicoClinicoSelecionado}"
							value="#{item.clone()}" />
					</p:commandButton>

				</p:column>

				<f:facet name="footer">
					<p:outputLabel value="Total de " />
					<p:outputLabel
						value="#{fn:length(historicoClinicoMB.lista)} registro(s)" />

				</f:facet>

			</p:dataTable>


		</h:form>

		<ui:include src="dialogCadastroHistoricoClinico.xhtml" />
		<ui:include src="/includes/confirmacaoExcluir.xhtml" />
	</ui:define>
</ui:composition>

